#include "main/utils.h"
using namespace std;

vector<int> findOrders(const int& course_num,
                       const vector<vector<int>> prerequisites) {
  map<int, vector<int>> graph;
  vector<int> indegrees(course_num, 0);
  for (int i = 0; i < prerequisites.size(); ++i) {
    auto pre = prerequisites[i][1];
    auto back = prerequisites[i][0];
    graph[pre].push_back(back);
    ++indegrees[back];
  }

  queue<int> queue;
  for (int i = 0; i < course_num; ++i) {
    if (indegrees[i] == 0) {
      queue.push(i);
    }
  }
  vector<int> ret;
  while (!queue.empty()) {
    int cur = queue.front();
    queue.pop();
    ret.push_back(cur);
    for (auto next : graph[cur]) {
      --indegrees[next];
      if (indegrees[next] == 0) {
        queue.push(next);
      }
    }
  }
  vector<int> null_vec;
  return ret.size() == course_num ? ret : null_vec;
}

int main() {
  vector<vector<int>> prerequisites = {{1, 0}, {2, 0}, {3, 1}, {3, 2}};
  int course_num = 4;
  auto orders = findOrders(course_num, prerequisites);
  printVec("o113", orders);

  return 0;
}
